/**
* @file init_callback_register.cpp
*
* Copyright (c) Huawei Technologies Co., Ltd. 2025. All Rights reserved.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/

#include "runtime/acl_rt_impl.h"
#include "error_codes_inner.h"
#include "common/log_inner.h"
#include "model/acl_resource_manager.h"

#ifdef __cplusplus
extern "C" {
#endif
extern __attribute__((weak, visibility("default"))) void conflicting_func_ascendcl();
#ifdef __cplusplus
}
#endif

namespace {
// --------------------------------initialize----------------------------------------------------------------------
aclError AclOpExecutorInitCallbackFunc(const char *configStr, size_t len, void *userData)
{
    (void)userData;
    ACL_LOG_INFO("start to enter AclOpExecutorInitCallbackFunc");

    if ((configStr != nullptr) && (len != 0UL)) {
        // config max_opqueue_num
        ACL_LOG_INFO("set max_opqueue_num in aclInit");
        auto ret = acl::AclResourceManager::GetInstance().HandleMaxOpQueueConfig(configStr);
        if (ret != ACL_SUCCESS) {
            ACL_LOG_INNER_ERROR("[Process][QueueConfig]process HandleMaxOpQueueConfig failed");
            return ret;
        }
        ACL_LOG_INFO("set HandleMaxOpQueueConfig success");
    }
    return ACL_SUCCESS;
}
__attribute__((constructor)) aclError RegAclOpExecutorInitCallback()
{
    return aclInitCallbackRegisterImpl(ACL_REG_TYPE_ACL_OP_EXECUTOR, AclOpExecutorInitCallbackFunc, nullptr);
}
__attribute__((destructor)) aclError UnRegAclOpExecutorInitCallback()
{
    if (conflicting_func_ascendcl == nullptr) {
        return aclInitCallbackUnRegisterImpl(ACL_REG_TYPE_ACL_OP_EXECUTOR, AclOpExecutorInitCallbackFunc);
    }
    return ACL_SUCCESS;
}
}